package library.and.xps.com.step.chatFormatter;

import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;

import java.util.ArrayList;

import library.and.xps.com.step.m.model.DaliyRecord;
import library.and.xps.com.step.util.DateUtil;

public class DayAxisValueFormatter implements IAxisValueFormatter {

    private BarLineChartBase<?> chart;
    private ArrayList<DaliyRecord> records;

    public DayAxisValueFormatter(BarLineChartBase<?> chart, ArrayList<DaliyRecord> records) {
        this.chart = chart;
        this.records = records;
    }

    @Override
    public String getFormattedValue(float value, AxisBase axis) {

        DaliyRecord re = records.get((int) value);
        if (re.getStepCount() == 0)
            return "";

        String simpleDateStr = DateUtil.formatDateSimple(re.getTimeStamp());
        int zeroIndex = simpleDateStr.indexOf("0");
        if (zeroIndex == 0) {
            simpleDateStr = simpleDateStr.replaceFirst("0", "");
        }

        return simpleDateStr;
    }

}
